<template>
  <!-- 搜索 -->
  <view class="cu-bar search bg-white action" id="item2">
    <view class="action" @tap="filtrate">
      <view class="icon iconfont icon-nianji" style="font-size: 40rpx"></view>
      <view style="font-size: 20rpx">{{ xuanze }}</view>
    </view>
  </view>
  <!-- 弹出选项 -->
  <view class="filter" :class="[show1 ? 'anim' : 'filter', show2 ? 'anim1' : 'filter']">
    <!-- 油卡过期等 单选 -->
    <view style="display: flex; justify-content: space-around">
      <view
        class="item"
        v-for="(item, index) in list"
        :key="index"
        @click="filterSelect(index, $event, item)"
      >
        <view :id="index" :class="selectShow === index ? 'selectOne' : ''">
          {{ item }}
          <view :class="selectShow === index ? 'sanjiaoxing' : ''"></view>
          <view :class="selectShow === index ? 'duihao' : ''">
            <u-icon name="checkmark" color="white" size="14"></u-icon>
          </view>
        </view>
      </view>
    </view>
    <!-- 确定 取消按钮 -->
    <view class="btns">
      <view @click="filtrate" class="btn" style="background-color: #6ca3fb; color: white">完成</view>
    </view>
  </view>
  <view class="qbu1">
    <u-collapse
      item-style="marginTop: '20px';border-bottom: 1px solid #ccc;background-color: #fff;   border-radius: 20rpx;"
      head-style="font-size: 35rpx;margin-left: 30rpx;"
      body-style="padding: 0 30rpx 0 30rpx;"
    >
      <view class="qbu">
        <u-collapse-item
          :title="item.zhangming"
          v-for="(item, index) in itemList"
          :key="index"
          style="font-weight: bold"
        >
          <view
            class="collapse-item"
            v-for="(item1, index1) in item.body"
            :key="index1"
            :class="item.body.length === index1 + 1 ? '' : 'dibu'"
          >
            <view class="item-title">
              <view style="font-size: 28rpx; font-weight: bold">{{ item1.xiaojieming }}</view>
              <view
                style="margin-top: 15rpx; color: #999999; font-size: 20rpx"
              >练习题共：{{ item1.content }}题</view>
            </view>
            <button
              shape="circle"
              plain
              type="primary"
              @tap="getSection(item1)"
              style="margin-right: 10rpx; width: 150rpx; color: #3e3c6df2"
            >去练习</button>
          </view>
        </u-collapse-item>
      </view>
    </u-collapse>
  </view>
</template>

<script lang="ts" setup>
import uniPopup from '../../components/components/uni-popup/uni-popup.vue'
// import uCollapse from '../../components/vk-uview-ui_1.5.2/components/u-collapse/u-collapse.vue'
// import uCollapseItem from '../../components/vk-uview-ui_1.5.2/components/u-collapse-item/u-collapse-item.vue'

import { getGradeContent } from '../../services/kaosi'
import { onLoad, onPageScroll } from '@dcloudio/uni-app'
import { guanzhuStore, myStore, ShouyeStore } from '@/stores'
import { reactive, ref, toRefs } from 'vue'
let item = ''
onLoad(async (e: any) => {
  // 监听全局关注和顶踩事件
  console.log(e)
  console.log(JSON.parse(e.item), '我看看111')
  item = JSON.parse(e.item)

  let res = await getGradeContent({ item, xuanze: xuanze.value })
  console.log(res, '获取对应数据')
  itemList.value = res.data
})
// 打开弹出层的组件
const show1 = ref(false)
const show2 = ref(false)
const list = ref(['上学期', '下学期'])
const clickBtn = ref('')
const selectShow = ref(-1)
const xuanze = ref('上学期')
const xuanze1 = ref('上学期')
const filtrate = async () => {
  console.log('触发了')

  show1.value = !show1.value
  show2.value = !show1.value
  xuanze.value = xuanze1.value
  let res = await getGradeContent({ item, xuanze: xuanze.value })
  console.log(res, '获取对应数据')
  itemList.value = res.data
}
const filterSelect = (index, e, item) => {
  if (selectShow.value === -1) {
    selectShow.value = index
    clickBtn.value = e.target.id
    xuanze1.value = item
  } else if (clickBtn.value === e.target.id) {
    selectShow.value = -1
  } else {
    selectShow.value = index
    clickBtn.value = e.target.id
    xuanze1.value = item
  }
}
// 折叠面板
const itemList = ref<any>([
  {
    head: '20以内的退位减法',
    body: [
      { title1: '十几减9', content: '5' },
      { title1: '十几减8、7、6', content: '5' },
      { title1: '十几减5、4、3、2、', content: '5' },
    ],
  },
  {
    head: '分类与整理',
    body: [
      { title1: '分类与整理', content: '5' },
      { title1: '单元复习', content: '5' },
    ],
  },
  {
    head: '100以内数的认识',
    body: [
      { title1: '数数 数的组成', content: '5' },
      { title1: '数的顺序 比较大小', content: '5' },
      { title1: '整十数加一位数及相应的减法', content: '5' },
      { title1: '单元复习', content: '5' },
    ],
  },
])
// 跳转题库中
const getSection = (item1) => {
  uni.navigateTo({
    url: '/pagesB/practice/index?section=' + JSON.stringify(item1),
  })
}
</script>

<style lang="scss">
@import url('../../static/assets/wxss/iconfont.css');
.top {
  // 加粗

  width: 100vw;
  height: 65px;
  background-color: rgba(248, 248, 248, 100);
  color: rgba(16, 16, 16, 100);
  font-size: 14px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 0 20px;
}

.date {
  color: rgba(36, 36, 36, 100);
  font-size: 17px;
}

.top-bottom {
  color: rgba(181, 179, 179, 100);
  font-size: 14px;
  margin-top: 5px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.icon-shaixuan {
  font-size: 15px;
  margin-left: 3px;
}

.filter {
  width: 100vw;
  height: 250rpx;
  background-color: white;
  color: rgba(16, 16, 16, 100);
  position: fixed;
  top: -150px;
  z-index: 1;
}

.item {
  margin-top: 25px;
  width: 250rpx;
  height: 36px;
  background-color: rgba(246, 245, 245, 100);
  line-height: 36px;
  text-align: center;
  border-radius: 20px;
}

.btns {
  position: absolute;
  bottom: 0;
  display: flex;
  width: 100%;
}

.btn {
  display: block;
  width: 80%;
  height: 47px;
  border-radius: 2px;
  background-color: #6c71fb;
  color: rgba(249, 80, 75, 100);
  display: flex;
  justify-content: center;
  // 圆润
  border-radius: 20px;
  align-items: center;
  margin-left: 70rpx;
}

.anim {
  animation: tobottom 0.3s ease-in;
  animation-fill-mode: forwards;
}

@keyframes tobottom {
  from {
    top: -150px;
  }

  to {
    top: 65px;
  }
}

.anim1 {
  animation: toTop 0.3s ease-in;
  animation-fill-mode: forwards;
}

@keyframes toTop {
  from {
    top: 65px;
  }

  to {
    top: -150px;
  }
}

.selectOne {
  border-radius: 2px;
  background-color: rgba(255, 241, 241, 100);
  position: relative;
  color: rgba(249, 80, 75, 100);
}

.sanjiaoxing {
  position: absolute;
  width: 0;
  height: 0;
  border-bottom: 18px solid #6ca3fb;
  border-left: 18px solid transparent;
  right: 0;
  bottom: 0;
}

.duihao {
  position: absolute;
  right: 2px;
  bottom: 2px;
  display: flex;
  align-items: flex-end;
}
.collapse-item {
  color: rgb(41, 37, 37);
  padding-bottom: 10px;
  width: 100%;
  display: flex;
  justify-content: space-evenly;
  align-items: center;
  font-size: 14px;
  margin-top: 30rpx;
}
.item-title {
  display: flex;
  // 方向垂直
  flex-direction: column;
  // 垂直隔开
  width: 75%;
}
.action {
  z-index: 5;
}
.qbu {
  width: 88%;
  height: 100%;
  margin-left: 50rpx;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 20px;
}
.qbu1 {
  width: 100%;

  margin-top: 30rpx;
  //  圆润
  border-radius: 40rpx;
}
.dibu {
  // 底部横线
  border-bottom: 1px solid #ccc;
}
page {
  background-color: rgb(249, 249, 249);
}
</style>
